//
//  LoadingUtil.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/3/7.
//

import UIKit

class ModelViewUtil: NSObject {
    var alertView: UIView!
    var container: LoadingView!
    static let shared = ModelViewUtil()
    
    //当前界面是否是横屏
    func showLoadingView(_ showText: String = R.string.localizable.loading()){
        if let rootVCView = Tool.getRootView(),self.container == nil{
            container = LoadingView()
            container.loadingLabel.text = showText
            rootVCView.addSubview(container)
            container.snp.makeConstraints { make in
                make.edges.equalToSuperview()
            }
        }
    }
    func hideLoadingView(){
        if let _ = self.container{
            self.container.actitveView.stopAnimating()
            self.container.removeFromSuperview()
            self.container = nil
        }
    }
    func hideUpdatingView(){
        if let _ = self.container{
            container.loadingLabel.text = R.string.localizable.updated()
            container.actitveView.stopAnimating()
            container.actitveView.isHidden = true
            container.imageView.isHidden = false
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0) {
                self.container.removeFromSuperview()
                self.container = nil
            }
        }
    }
    //MARK: - 将参数view（随便什么弹出框），弹出来
    func showAlertView(_ view: UIView){
        guard let rootVCView = Tool.getRootView() else {
            return
        }
        
        rootVCView.addSubview(view)
        view.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
}
